%% Haar wavelet transform
inImg = imread('../1LAB/images/circuit.tif');

[im1 Wm Wn] = lab2dht(inImg);
outIm = lab2idht(im1,Wm,Wn);
imshow(outIm);
%% Iterated Haar transform
[im2 Wm2 Wn2] = lab2dht(im1(1:size(im1,1)/2,1:size(im1,2)/2));

outIm = lab2idht(im1,Wm,Wn);

im3 = im1;
im3(1:size(im3,1)/2,1:size(im3,2)/2)=im2;

imshow(mat2gray(im3))

%% Quantization with Lloyds algorithm
inImg = imread('../1LAB/images/lena.gif');
outImg = lab2lloyds(inImg,16);
imshow(mat2gray(outImg))
[imMS imPSNR] = imMSE(inImg,outImg)

%% Quantization of DCT
inImg = imread('../1LAB/images/lena.gif');

dctImg = dct(inImg);
outDct = lab2lloyds(dctImg,4);
outDct = idct(outDct);
[imMS imPSNR] = imMSE(inImg,outDct)
imshow(mat2gray(outDct))

%% Quantization of DWT Debouchies and Haar
wavType = 'db4';
numLev = 4;
inImg = imread('../1LAB/images/lena.gif');
outDwt = lab2quantTest(inImg,wavType,numLev,1);
[imMS imPSNR] = imMSE(inImg,outDwt)
imshow(mat2gray(outDwt))

%% Iterative Haar
wavType = 'haar';
numLev = 4;
haarIt = 2;
inImg = imread('../1LAB/images/lena.gif');

outDwt = lab2quantTest(inImg,wavType,numLev,haarIt);
[imMS imPSNR] = imMSE(inImg,outDwt)

imshow(mat2gray(outDwt))

